{extend name="public/base"/}
{block name="body"}
<title>企业文化设置</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span>关于我们<span class="c-gray en">&gt;</span> 企业文化设置<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<article class="page-container">
		<form class="form form-horizontal section" id="form-admin-add">
			<section>
					<input type="hidden" class="input-text" value="{$data.id}" id="id" name="id">
					<div class="row cl">
						<label class="form-label col-xs-3 col-sm-2">SEO关键词：</label>
						<div class="formControls col-xs-8 col-sm-9">
							<input type="text" class="input-text" value="{$data.seo_keywords}" id="seo_keywords" name="seo_keywords">
						</div>
					</div>
					<div class="row cl">
						<label class="form-label col-xs-3 col-sm-2">SEO描述：</label>
						<div class="formControls col-xs-8 col-sm-9">
							<input type="text" class="input-text" value="{$data.seo_description}" id="seo_description" name="seo_description">
						</div>
					</div>
					<div class="row cl">
						<label class="form-label col-xs-3 col-sm-2">标题：</label>
						<div class="formControls col-xs-8 col-sm-9">
							<input type="text" class="input-text" value="{$data.title}" id="title" name="title">
						</div>
					</div>
					<div class="row cl">
						<label class="form-label col-xs-3 col-sm-2">副标题：</label>
						<div class="formControls col-xs-8 col-sm-9">
							<input type="text" class="input-text" value="{$data.title_en}" id="title_en" name="title_en">
						</div>
					</div>
					<div class="row cl">
						<label class="form-label col-xs-3 col-sm-2">图片：</label>
						<div class="formControls col-xs-8 col-sm-9">
			                <div style="position:relative;" id="drop_area"></div>
			                <p style="color:#ccc;font-size:12px;">建议尺寸宽高:285*438</p>
						</div>
					</div>
			</section>

					<div class="row cl">
						<div class="col-xs-8 col-sm-9 col-xs-offset-3 col-sm-offset-2">
							<input id="submit" class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
						</div>
					</div>
		</form>
		
</article>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/public/static/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="/public/static/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="/public/static/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="/public/static/js/upload.js"></script>
<script type="text/javascript">
var formData = new FormData();
var img;
$(function(){
	$('#drop_area div img').attr('src','/public{$data.img}');
	$('#drop_area div img').attr('onerror',"javascript:this.src='/public/static/img/upload.png'");
	if($("#drop_area div img").attr('src')=='/public/static/img/upload.png'){
		img='';
	}else{
		img= `{$data.img}`;
	}
});
var dragImgUpload = new DragImgUpload("#drop_area",{
    callback:function (files) {
        //回调函数，可以传递给后台等等
        if(files[0].size<3145728){
	        var file = files[0];
	        formData.append("file",file);
        }else{
        	alert('出错');
        	location.replace(location.href);
        }
    }
});
$("#submit").click(function() {
	layer.load(1, {
	  shade: [0.1,'#fff'] //0.1透明度的白色背景
	});
	var title=$("input[name=title]").val();
	var title_en=$("input[name=title_en]").val();
	var seo_keywords=$("input[name=seo_keywords]").val();
	var seo_description=$("input[name=seo_description]").val();
	if(formData.get("file")){
		$.ajax({
	          type: 'POST',
	          url: "{:url('uploadtmd')}",
	          data:formData,
	          contentType: false, /*不可缺*/
	          processData: false, /*不可缺*/
	          success: function(response){
	            if(response.code==200){
	            	img=response.photo;
	            	$.ajax({
					    type: 'POST',
					    url: "{:url('culture_set')}",
					    data: {title:title,img:img,title_en:title_en,seo_description:seo_description,seo_keywords:seo_keywords},
					    success: function(resdata){
					        if(resdata.code==200){
								layer.msg(resdata.msg,{icon:1,time:1000});
								setTimeout("parent.location.reload()",1000);
					        }else{
								layer.msg(resdata.msg,{icon:2,time:3000});
					        }
					    },
					    error: function(){
							layer.msg('数据保存失败',{icon:2,time:3000});
					    }
					})
	            }else{
	              alert(response.msg);
	            }
	          },
	          error: function(err){

	          }
	    })
	}else{
		$.ajax({
		    type: 'POST',
		    url: "{:url('culture_set')}",
		    data: {title:title,img:img,title_en:title_en,seo_description:seo_description,seo_keywords:seo_keywords},
		    success: function(resdata){
		        if(resdata.code==200){
					layer.msg(resdata.msg,{icon:1,time:1000});
					setTimeout("parent.location.reload()",1000);
		        }else{
					layer.msg(resdata.msg,{icon:2,time:3000});
		        }
		    },
		    error: function(){
				layer.msg('数据保存失败',{icon:2,time:3000});
		    }
		})
	}
    
})

</script> 

{/block}